package com.four.seckill.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.four.seckill.entity.CategoryEntity;
import com.four.seckill.mapper.CategoryMapper;
import com.four.seckill.service.CategoryService;
import com.four.seckill.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @Author: hxw
 * @Date: 2022/01/06/11:31
 * @Description
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<CategoryEntity> getList() {

        return categoryMapper.getList();
    }

    /**
     * 商品分类分页查
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage<CategoryEntity> categoryList(Integer page, Integer size, CategoryVo vo) {
        Page<CategoryEntity> categoryPage=new Page<>(page,size);
        return categoryMapper.categoryList(categoryPage,vo);
    }

    /**
     * 添加分类
     * @param category
     */
    @Override
    public void addCategory(CategoryEntity category) {
        categoryMapper.addCategory(category);
    }

    /**
     * 删除分类
     * @param catId
     */
    @Override
    public void deleteById(Integer catId) {
        categoryMapper.deleteById(catId);
    }

    /**
     * 根据商品查询商品分类
     * @param catId
     * @return
     */
    @Override
    public CategoryEntity getCategoryById(Integer catId) {
        return categoryMapper.getCategoryById(catId);
    }

    /**
     * 根据id修改商品分类
     * @param catId
     */
    @Override
    public void updateCategoryById(Integer catId,CategoryEntity category) {
        category.setCatId(catId);
        categoryMapper.updateCategoryById(category);
    }
}
